package Test;

public class 大数相加 {
    public static String addStrings(String num1, String num2) {
        int m=num1.length()-1;
        int n=num2.length()-1;
        int add=0;
        StringBuffer sb=new StringBuffer();
        while (m>=0||n>=0||add!=0){
            int x=m>=0?num1.charAt(m)-'0':0;
            int y=n>=0?num2.charAt(n)-'0':0;
            int sum=x+y+add;
            sb.append(sum%10);
            add=sum/10;
            m--;
            n--;
        }
        sb=sb.reverse();
        String res=sb.toString();
        return res;
    }

    public static void main(String[] args) {
        String s="123";
        String s1="111";
        System.out.println(addStrings(s,s1));
    }
}
